/*
 * @Author: LiJia
 * @Date: 2021-02-27 10:35:46
 * @LastEditTime: 2021-02-27 13:11:09
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \test\src\server.ts
 */

import express from 'express'
import bodyParser from 'body-parser'
import modules from './modules'

const app = express()

app.all("*", function (req, res, next) {
  //设置允许跨域的域名
  res.header("Access-Control-Allow-Origin", "*")
  //允许的header类型
  res.header("Access-Control-Allow-Headers", "content-type")
  //跨域允许的请求方式 
  res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS")
  if (req.method.toLowerCase() == 'options') {
    res.send(200)
  } else {
    next()
  }
})

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

// 登录接口
app.use(modules.accountApi.loginApi)

export default app
